<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <link rel="stylesheet" href="__ADMIN__/wx/css/default.css">
        <script type="text/javascript" src="__ADMIN__/wx/js/jquery-1.6.4.min.js"></script>
        <script type="text/javascript" src="__ADMIN__/wx/js/jquery.form.js"></script>
		<link rel="stylesheet" href="__ADMIN__/js/plugins/code/prettify.css" />
		<script charset="utf-8" src="__ADMIN__/js/plugins/kindeditor/kindeditor-all-min.js"></script>
		<script charset="utf-8" src="__ADMIN__/lang/zh_CN.js"></script>
		<script charset="utf-8" src="__ADMIN__/js/plugins/code/prettify.js"></script>
		<style type="text/css">
			.demo{width:620px; margin:30px auto}
			.demo p{line-height:32px}
			.btnfile{position: relative;overflow: hidden;margin-right: 4px;display:inline-block;*display:inline;padding:4px 10px 4px;font-size:14px;line-height:18px;*line-height:20px;color:#fff;text-align:center;vertical-align:middle;cursor:pointer;background-color:#5bb75b;border:1px solid #cccccc;border-color:#e6e6e6 #e6e6e6 #bfbfbf;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;}
			.btnfile input {position: absolute;top: 0; right: 0;margin: 0;border: solid transparent;opacity: 0;filter:alpha(opacity=0); cursor: pointer;}
			.progress { position:relative; margin-left:100px; margin-top:-24px; width:200px;padding: 1px; border-radius:3px; display:none}
			.bar {background-color: green; display:block; width:0%; height:20px; border-radius: 3px; }
			.percent { position:absolute; height:20px; display:inline-block; top:3px; left:2%; color:#fff }
			.files{height:22px; line-height:22px; margin:10px 0}
			.delimg{margin-left:20px; color:#090; cursor:pointer}
			.place{height:40px; background:url(__ADMIN__/images/righttop.gif) repeat-x;}
			.place span{line-height:40px; font-weight:bold;float:left; margin-left:12px;}
			.placeul li{float:left; line-height:40px; padding-left:7px; padding-right:12px; background:url(__ADMIN__/images/rlist.gif) no-repeat right;}
			.placeul li:last-child{background:none;}
		</style>
    </head>
    <body>
    	<div class="place">
		    <span>位置：</span>
		    <ul class="placeul">
		    	<li>首页</li>
		    	<li>添加资讯速递</li>
		    </ul>
		</div>
        <div class="col_main">
        	<form action="{:U('add')}" method="post">
            <div class="main_bd">
                <div class="media_edit_area">
                    <div id="js_appmsg_editor">
                        <div class="appmsg_editor" style="margin-top: 0px;">
                            <div class="inner">
                                <div class="appmsg_edit_item">
                                    <label for="" class="frm_label">标题</label>
                                    <span class="frm_input_box"><input type="text" class="frm_input js_title" name="title" value=""/></span>
                                </div>
                                <div class="appmsg_edit_item">
                                    <label for="" class="frm_label">
                                        <strong class="title">缩略图</strong>
                                        <p class="js_cover_tip tips">（大图片建议尺寸：145像素 * 95像素）</p>
                                    </label>
                                    <div class="upload_wrap">
                                       	<div class="upload_box">
                                        	<input type="hidden" name="img_path" id="zixun_img_path"/>
                                            <div class="upload_area">
                                            <div class="btnfile">
									            <span>上传</span>
									            <input id="fileupload" type="file" name="mypic">
									        </div>
									        <div class="progress">
									    		<span class="bar"></span><span class="percent">0%</span >
											</div>
									        <div class="files"></div>
									        <div id="showimg"></div>
                                        </div>
                                    </div>
                                    <div class="js_desc_area dn appmsg_edit_item" id="appmsg_zhaiyao">
										<label for="" class="frm_label">摘要</label>
										<span class="frm_textarea_box"><textarea class="js_desc frm_textarea" id="zixun_textarea_zhaiyao" name="article_desc"></textarea></span>
									</div>
                                </div>
                                <div id="js_ueditor" class="appmsg_edit_item content_edit">
                                    <label for="" class="frm_label">
                                        <strong class="title">正文</strong>
                                        <p class="tips">
                                            <em id="js_auto_tips">（自动保存：2014/08/08 16:20:12）</em>
                                            <div style="margin-top: 20px;float: left;"> 
                                            	<textarea name="content" id="content"></textarea>
                                            </div>
                                        </p>
                                    </label>
                                </div>
                                <i class="arrow arrow_out" style="margin-top: 0px;"></i>
                                <i class="arrow arrow_in" style="margin-top: 0px;"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="tool_area">
                    <div class="tool_bar border tc">
                        <span id="js_submit" class="btn btn_input btn_primary"><button type="submit">保存</button></span>
                    </div>
                </div>
            </div>
        </div>
        </form>
        <script type="text/javascript">
	        KindEditor.ready(function(K) {
	        	var editor1 = K.create('textarea[name="content"]', {
	        		cssPath : '__ADMIN__/js/plugins/code/prettify.css',
	        		uploadJson : '__PUBLIC__/lib/upload_json.php',
	        		width : "117%", //编辑器的宽度为70%
	        	    height : "360px", //编辑器的高度为100px
	        		fileManagerJson : '__PUBLIC__/lib/file_manager_json.php',
	        		items:['source', 'undo', 'redo',
	        		       'justifyleft', 'justifycenter', 'justifyright',
	        		       'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent','selectall',
	        		       'title', 'bold',
	        		       'italic', 'underline','image','multiimage','removeformat','|', 'fullscreen'],
	        		allowFileManager : true,
	        		afterCreate : function() {
	        			var self = this;
	        			K.ctrl(document, 13, function() {
	        				self.sync();
	        				K('form[name=example]')[0].submit();
	        			});
	        			K.ctrl(self.edit.doc, 13, function() {
	        				self.sync();
	        				K('form[name=example]')[0].submit();
	        			});
	        		}
	        	});
	        	prettyPrint();
	        });
        	
        	$(function () {
        		var bar = $('.bar');
        		var percent = $('.percent');
        		var showimg = $('#showimg');
        		var progress = $(".progress");
        		var files = $(".files");
        		var btn = $(".btnfile span");
        		$("#fileupload").wrap("<form id='myupload' action='{:U('/Admin/Article/ajaxUploadImg')}' method='post' enctype='multipart/form-data'></form>");
        	    $("#fileupload").change(function(){
       	    		$("#myupload").ajaxSubmit({
           				dataType:  'json',
           				beforeSend: function() {
           					progress.show();
           	        		var percentVal = '0%';
           	        		bar.width(percentVal);
           	        		percent.html(percentVal);
           					btn.html("上传中...");
           	    		},
           	    		uploadProgress: function(event, position, total, percentComplete) {
           	        		var percentVal = percentComplete + '%';
           	        		bar.width(percentVal);
           	        		percent.html(percentVal);
           	    		},
           				success: function(data) {
           					files.html("<b>"+data.name+"("+data.size+"k)</b> <span class='delimg' rel='"+data.pic+"'>删除</span>");
           					var img = data.url;
           					showimg.html("<img src='"+img+"' style='width:145px; height:95px;'>");
           					$("#new_img_default").attr("src", img);
           					$("#zixun_img_path").val(data.name);
           					$(".appmsg_thumb").show();
           					btn.html("上传");
           				},
           				error:function(xhr){
           					btn.html("上传失败");
           					bar.width('0')
           					files.html(xhr.responseText);
           				}
           			});
        		});
        		
        		$(".delimg").live('click',function(){
        			var pic = $(this).attr("rel");
        			$.post("{:U('ajaxDeleteImg')}",{imagename:pic},function(msg){
        				if(msg==1){
        					files.html("删除成功.");
        					showimg.empty();
        					progress.hide();
        					$("#new_img_default").attr("src", "");
        					$(".appmsg_thumb").hide();
        					$("#zixun_img_path").val("");
        					$(".default").show();
        				}else{
        					alert(msg);
        				}
        			});
        		});
        	});
        </script>
    </body>
</html>